import type { ConsultType } from '@/enums'
import type { KnowledgePage, KnowledgeParams, PageParams, DoctorPage, FollowType, TopDep, Image, ConsultOrderPreParams, ConsultOrderPreData, PartialConsult, ConsultOrderItem } from '@/types/consult'
import type { Patient } from '@/types/user'
import { request } from '@/utils/request'
import type { ConsultOrderListParams, ConsultOrderPage } from '@/types/consult'


// 文章分页数据
export const getKnowledgePage = (params: KnowledgeParams) => {
  return request<KnowledgePage>('/patient/home/knowledge', 'GET', params)
}
//  获取推荐关注医生
export const getDoctorPage = (params: PageParams) => {
  return request<DoctorPage>('/home/page/doc', 'GET', params)
}

// 关注医生  或者取消关注
export const followDoctor = (id: string, type: FollowType = 'doc') => {
  return request('/like', 'POST', { id, type })
}

// 获取科室

export const getAllDep = () => {
  return request<TopDep[]>('/dep/all')
}

// 上传图片
export const uploadImage = (file: File) => {
  const fd = new FormData()
  fd.append('file', file)
  return request<Image>('/upload', 'POST', fd)
}

//  拉取 预支付订单信息 后台根据 问诊类型 和极速问诊就别 确定金额
export const getConsultOrderPre = (params: ConsultOrderPreParams) => {
  return request<ConsultOrderPreData>('/patient/consult/order/pre', 'GET', params)
}

// 根据id查询患者详情
export const getPatientDetail = (id: string) => {
  return request<Patient>(`/patient/info/${id}`, 'GET')
}

// 生成订单
export const createConsultOrder = (data: PartialConsult) => {
  return request<{ id: string }>('/patient/consult/order', 'POST', data)
}

// 获取支付地址 0是微信  1是支付宝
export const getConsultOrderPayUrl = (data: { paymentMethod: 0 | 1; orderId: string; payCallback: string }) => {
  return request<{ payUrl: string }>('/patient/consult/pay', 'POST', data)
}
// 订单详情
export const getConsultOrderDetail = (orderId: string) => {
  return request<ConsultOrderItem>('/patient/consult/order/detail', 'GET', { orderId })
}
// 查看处方
export const getPrescriptionPic = (id: string) => {
  return request<{ url: string }>(`/patient/consult/prescription/${id}`)
}
// 评价问诊
export const evaluateConsultOrder = (data: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: 0 | 1
}) => request<{ id: string }>('/patient/order/evaluate', 'POST', data)

// 问诊记录分页
export const getConsultOrderList = (params: ConsultOrderListParams) =>
  request<ConsultOrderPage>('/patient/consult/order/list', 'GET', params)

// 取消订单
export const cancelOrder = (id: string) => request(`/patient/order/cancel/${id}`, 'PUT')
